package org.mat.ipaas.ucenter.bff.admin.modules.oss.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.mat.framework.lang.dto.MatApiResponse;
import org.mat.ipaas.ucenter.service.api.oss.OssFileRestAPI;
import org.mat.ipaas.ucenter.service.dto.oss.entity.OssFileDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * 云存储示例 DEMO
 */
@Slf4j
@Controller
@RequestMapping("/sys/oss/file")
public class OssFileController {

	@Autowired
	private OssFileRestAPI ossFileRestAPI;

	@ResponseBody
	@GetMapping("/list")
	public MatApiResponse<IPage<OssFileDTO>> queryPageList(OssFileDTO file,
														   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
														   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
		MatApiResponse<IPage<OssFileDTO>> matApiResponse = ossFileRestAPI.queryPageList(file, pageNo, pageSize, req);
		return matApiResponse;
	}

	@ResponseBody
	@PostMapping("/upload")
	//@RequiresRoles("admin")
    //@RequiresPermissions("system:ossFile:upload")
	public MatApiResponse upload(@RequestParam("file") MultipartFile multipartFile) {
		MatApiResponse matApiResponse = ossFileRestAPI.upload(multipartFile);
		return matApiResponse;
	}

	@ResponseBody
	@DeleteMapping("/delete")
	public MatApiResponse delete(@RequestParam(name = "id") String id) {
		MatApiResponse matApiResponse = ossFileRestAPI.delete(id);
		return matApiResponse;
	}

	/**
	 * 通过id查询.
	 */
	@ResponseBody
	@GetMapping("/queryById")
	public MatApiResponse<OssFileDTO> queryById(@RequestParam(name = "id") String id) {
		MatApiResponse<OssFileDTO> matApiResponse = ossFileRestAPI.queryById(id);
		return matApiResponse;
	}

}
